package org.hackystat.sdsa.analyzer.control.compressor;

import static org.junit.Assert.assertEquals;

import java.util.ArrayList;
import java.util.List;

import org.hackystat.sdsa.analyzer.model.activity.Activity;
import org.junit.Test;

/**
 * Test the edit activity compressor.
 * 
 * @author hongbing
 *
 */
public class TestEditCompressor extends CompressorTestCommon {
  /**
   * Tests compression of doc edit activities.
   * 
   * @throws Exception If error in testing.
   */
  @Test public void testDocEditCompressor() throws Exception {
    EditCompressor compressor = new EditCompressor();
    List<Activity> editActivityList = new ArrayList<Activity>();
    editActivityList.addAll(super.docActivityList);

    assertEquals("Test size before compression", 4, editActivityList.size());
    compressor.compress(editActivityList);
    assertEquals("Test size after compression", 2, editActivityList.size());
    
    Activity firstDocEdit = editActivityList.get(0);
    assertEquals("Test first doc file", "package.html", firstDocEdit.getResourceFile());
    assertEquals("Test first activity data ", "110sec FI=+27(127)", 
        firstDocEdit.getRepresentation());
    
    Activity secondDocEdit = editActivityList.get(1);
    assertEquals("Test second doc file", "index.jsp", secondDocEdit.getResourceFile());
    assertEquals("Test second activity data ", "0sec FI=0(560)", secondDocEdit.getRepresentation());
  }


  /**
   * Tests compression of prod edit activities.
   * 
   * @throws Exception If error in testing.
   */
  @Test public void testProdEditCompressor() throws Exception {
    EditCompressor compressor = new EditCompressor();
    List<Activity> editActivityList = new ArrayList<Activity>();
    editActivityList.addAll(super.prodActivityList);

    assertEquals("Test prod size before compression", 5, editActivityList.size());
    compressor.compress(editActivityList);
    assertEquals("Test prod size after compression", 2, editActivityList.size());
    
    Activity firstProdEdit = editActivityList.get(0);
    assertEquals("Test first prod file", "Foo.java", firstProdEdit.getResourceFile());
    assertEquals("Test first prod activity data ", "110sec MI=+8(8), SI=+930(930), FI=+27(127)", 
        firstProdEdit.getRepresentation());

    
    Activity secondProdEdit = editActivityList.get(1);
    assertEquals("Test second doc file", "Bar.java", secondProdEdit.getResourceFile());
    assertEquals("Test second prod activity data ", "110sec MI=+3(3), SI=+30(30), FI=+70(80)", 
        secondProdEdit.getRepresentation());
  }

  /**
   * Tests compression of tests edit activities.
   * 
   * @throws Exception If error in testing.
   */
  @Test public void testTestEditCompressor() throws Exception {
    EditCompressor compressor = new EditCompressor();
    List<Activity> editActivityList = new ArrayList<Activity>();
    editActivityList.addAll(super.testActivityList);

    assertEquals("Test test size before compression", 5, editActivityList.size());
    compressor.compress(editActivityList);
    assertEquals("Test test size after compression", 2, editActivityList.size());
    
    Activity firstTestEdit = editActivityList.get(0);
    assertEquals("Test test file", "TestFoo.java", firstTestEdit.getResourceFile());
    assertEquals("Test test activity data ", 
        "110sec MI=+8(8), SI=+930(930), TI=+7(7), AI=+8(8), FI=+27(127)", 
        firstTestEdit.getRepresentation());
    
    Activity secondTestEdit = editActivityList.get(1);
    assertEquals("Test second test file", "TestBar.java", secondTestEdit.getResourceFile());
    assertEquals("Test second test activity data", 
        "110sec MI=+3(3), SI=+30(30), TI=+1(1), AI=+13(13), FI=+70(80)", 
        secondTestEdit.getRepresentation());
  }
  
  /**
   * Test compressor when contains all three types of edit activities.
   * 
   * @throws Exception If problem occurs.
   */
  @Test public void testAllEditActivityCompressor() throws Exception {
    EditCompressor compressor = new EditCompressor();
    List<Activity> editActivityList = new ArrayList<Activity>();
    editActivityList.addAll(super.allEditActivityList);

    assertEquals("Test all size before compression", 14, editActivityList.size());
    compressor.compress(editActivityList);
    assertEquals("Test all size after compression", 6, editActivityList.size());
  }
}
